package com.demo.mykotlin

import android.app.Activity

/**
 * 活动收藏（单例）类
 * @author wen66to88@163.com
 * @date 2020/5/27 - 13:57
 */
object ActivityCollector {
    private val activities = ArrayList<Activity>()
    fun addActivity(activity: Activity) {
        activities.add(activity)
    }

    fun removeActivity(activity: Activity) {
        activities.remove(activity)
    }

    fun finishAll() {
        for (activity in activities) {
            if (!activity.isFinishing) {
                activity.finish()
            }
        }
        activities.clear()
    }

}